/*
 * Phys2D - a 2D physics engine based on the work of Erin Catto. The
 * original source remains:
 * 
 * Copyright (c) 2006 Erin Catto http://www.gphysics.com
 * 
 * This source is provided under the terms of the BSD License.
 * 
 * Copyright (c) 2006, Phys2D
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or 
 * without modification, are permitted provided that the following 
 * conditions are met:
 * 
 *  * Redistributions of source code must retain the above 
 *    copyright notice, this list of conditions and the 
 *    following disclaimer.
 *  * Redistributions in binary form must reproduce the above 
 *    copyright notice, this list of conditions and the following 
 *    disclaimer in the documentation and/or other materials provided 
 *    with the distribution.
 *  * Neither the name of the Phys2D/New Dawn Software nor the names of 
 *    its contributors may be used to endorse or promote products 
 *    derived from this software without specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 
 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 
 * OF SUCH DAMAGE.
 */
package com.phys2d.trashball;

import java.awt.Point;
import java.io.IOException;

import com.phys2d.trashball.objects.DrawableBox;
import com.phys2d.trashball.objects.DrawableCircle;
import com.phys2d.trashball.objects.DrawablePolygon;

import net.phys2d.math.Vector2f;
import net.phys2d.raw.BasicJoint;
import net.phys2d.raw.Body;
import net.phys2d.raw.FixedJoint;
import net.phys2d.raw.StaticBody;
import net.phys2d.raw.World;
import net.phys2d.raw.shapes.Box;
import net.phys2d.raw.shapes.Circle;
import net.phys2d.raw.shapes.ConvexPolygon;
import net.phys2d.raw.shapes.DynamicShape;
import net.phys2d.raw.shapes.Line;

/**
 * Lines
 * 
 * @author Kevin Glass
 */
public class Demo15 extends TrashWorld {
	/**
	 * Create the demo
	 */
	public Demo15() {
		super("Phys2D Demo 15 - Line vs Box");
	}

	/**
	 * @see net.phys2d.raw.test.AbstractDemo#init(net.phys2d.raw.World)
	 */
	protected void init(World world) {
		try {
		
		Body land = new StaticBody("Piso", new Line(700,0));
		land.setPosition(50,401);
		land.setRestitution(0.6f);
//		land.setFriction(0.8f);
		world.add(land);
		
		Body pared = new StaticBody("Pared", new Line(0,500));
		pared.setPosition(790,0);
		pared.setRestitution(0.6f);
//		land.setFriction(0.8f);
		world.add(pared);
		
		DrawableBox chairrr = new DrawableBox(20,20);
		chairrr.setImage(Resources.getImage(Resources.Images.OFFICE_CHAIR));
		Body chairBod = new StaticBody("Chairr", chairrr);
		
		chairBod.setPosition(200, 150);
		
		world.add(chairBod);
//		Body tachoFrente = new StaticBody("TachoFrente", new Line(0,40));
//		tachoFrente.setPosition(350,350);
//		world.add(tachoFrente);
//		
//		Body tachoAtras = new StaticBody("TachoAtras", new Line(0,40));
//		tachoAtras.setPosition(400,350);
//		world.add(tachoAtras);
		
		//		DrawableBox fr = new DrawableBox(50,50);
		
//		Vector2f[] triangleVerts = {new Vector2f(605,336) 
//			, new Vector2f(672,336) 
//			, new Vector2f(693,232)
//			, new Vector2f(671,352)
//			, new Vector2f(680,232)
//			, new Vector2f(662,321) 
//			, new Vector2f(611,321) 
//			, new Vector2f(594,232) 
//			, new Vector2f(579,232)
//			, new Vector2f(605,336)
//		};
//		DrawablePolygon trashCanPoly = new DrawablePolygon(triangleVerts);
//		Body trashCan = new Body("TrashCan",trashCanPoly,100);
//		trashCan.setRestitution(0.7f);
//		trashCan.setFriction(0.1f);
//		world.add(trashCan);
		
		
//			DrawableCircle trashBall = new DrawableCircle(20);
//			trashBall.setImage(Resources.getImage(Resources.Images.TRASHBALL));
//			Body ball = new Body("TrashBall" , trashBall,1);
//			ball.setPosition(50, 350);
//			ball.setRotatable(true);
//			ball.setRotation((float) Math.toRadians(65));
//			ball.setRestitution(1);
//			ball.setForce(2000, -3400);
//			world.add(ball);
		
		
			DrawableBox fallerBox = new DrawableBox(50,50);
			fallerBox.setImage(Resources.getImage(Resources.Images.WOODEN_BOX));
			Body box = new Body("Faller", fallerBox , 1);
			box.setPosition(150,100);
			box.setRotation(0.5f);
			
			world.add(box);
			
			DrawableBox fallerBox3 = new DrawableBox(50,50);
			fallerBox3.setImage(Resources.getImage(Resources.Images.WOODEN_BOX));
			Body box3 = new Body("Faller3", fallerBox3 , 1);
			box3.setPosition(250,300);
			box3.setRotation(0.5f);
			world.add(box3);
			
			Box fr = new Box(10,50);
			Body frA = new Body("TachoFrente", fr , 10);
			frA.setPosition(345, 372);
			frA.setRestitution(0.7f);
			frA.setRotation((float) Math.toRadians(-10));
			world.add(frA);
			
			Box frb = new Box(10,50);
			Body frB = new Body("TachoAtras", frb , 10);
			frB.setPosition(395, 372);
			frB.setRestitution(0.7f);
			frB.setRotation((float) Math.toRadians(10));
			world.add(frB);
			
			DrawableBox base = new DrawableBox(50,5);
			base.setImage(Resources.getImage(Resources.Images.TRASH_CAN));
			base.setImagePosition(new Point(0, -50));
			Body frBase = new Body("TachoBase", base , 10);
			frBase.setPosition(370, 400);
			world.add(frBase);
			
			FixedJoint j = new FixedJoint(frA,frBase);
			world.add(j);
			
			FixedJoint z = new FixedJoint(frBase,frB);
			world.add(z);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * Entry point for tetsing
	 * 
	 * @param argv The arguments to the test
	 */
	public static void main(String[] argv) {
		Demo15 demo = new Demo15();
		try {
			demo.start();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
